/*replication code for preparing data for "Endless Nightmare" Torture and Inhuman Treatment in Solitary Confinement in U.S. Immigration Detention (02/06/2024).
Uses SRMS data on solitary confinement in the U.S. immigration detention facilities from 2018 to 2023, obtained by the Harvard Immigration and Refugee Clinical Program
Stata version 17*/

***PREPARE DATA**

**********IMPORT DATA***********
import excel "SRMS spreadsheet 9.1.2018 - 9.1.2023 Redacted.xlsx", sheet("2017 - 2023") firstrow clear

**********CLEAN DATA************
*there are 3019 rows with values for suicide risk variable, with all other variables missing. This data cannot be used and is dropped.
drop if TrackingNumber=="" 			// 3019 dropped

*155 detainees were still in confinement on the day data was produced by ICE. These cases have a missing Release date. These cases are not included in the length calculation, as their placement in solitary confinement was  not over.
replace Length=. if ReleaseD==.		// 155 changed to missing, sample size for Length is 14,109

*standardize the mental illness indicator variable
replace MentalI="Mental Illness" if MentalI=="Yes" 	// 1 change made

*standardize the facility variable
replace Facility="WEBB COUNTY DETENTION CENTER (CCA) (TX)" if Facility=="WEBB COUNTY DETENTION CENTER (TX)" // 1 change made

*generate variables used for the analysis
gen PlacementY=year(PlacementD)		// Year of placement in solitary confinement
gen ReleaseY=year(ReleaseD)			// Year of release from solitary confinement
gen PlacementM=month(PlacementD)	// Month of placement in solitary confinement
gen PlacementQ=qofd(PlacementD) 	// Quarter of placement in solitary confinement
format %tq PlacementQ

gen Mental_bin=cond(MentalI=="Mental Illness" | MentalI=="Serious Mental Illness" | MentalI=="Yes", 1, cond(Mental=="None", 0, .)) // variable indicating whether the detainee has mental illness (1) or no (0)
gen SeriousMental=cond(MentalI=="Serious Mental Illness", 1, cond(MentalI=="Mental Illness", 0, .)) // variable indicating whether the detainee has  serious mental illness (1) or mental illness (0)

*create value label
label define yesno 1 "Yes" 0 "No"
label values Mental_bin yesno
label values SeriousMental yesno

**********SAVE DATA***********
save srms_data.dta, replace